import { Controller, Get, Post, Body, Patch, Param, Delete, Put, HttpCode, HttpStatus, Req } from '@nestjs/common';
import { Request } from 'express';
import { UserService } from './user.service';
import { User } from './entities/user.entity'
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { Public } from '../auth/decorators/public.decorator';

@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Public()
  @Post('register')
  @HttpCode(HttpStatus.OK)
  async register(@Body() createUserDto: CreateUserDto) {
    await this.userService.create(createUserDto);
    return ''
  }

  @Post('query/page')
  findPage(@Body() condition: User) {
    return this.userService.findPage(condition);
  }

  @Get('query/list')
  findAll(@Body() condition: User) {
    return this.userService.findAll(condition);
  }

  @Get('query/one')
  findOne(@Param('id') id: string) {
    return this.userService.findOne(id);
  }

  @Get('query/cur')
  findCur(@Req() request: Request) {
    return this.userService.findCur(request);
  }

  @Put('update')
  update(@Body() updateUserDto: UpdateUserDto, @Req() request: Request) {
    return this.userService.update(updateUserDto, request);
  }

  @Delete('delete')
  remove(@Param('id') id: string) {
    return this.userService.remove(id);
  }
}
